#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
FABRIC_CA=$GOPATH/src/github.com/tjfoc/gmca
SCRIPTDIR="$FABRIC_CA/scripts/fvt"
. $SCRIPTDIR/fabric-ca_utils
export RESULTLOG="/tmp/fvt-test.results"
export STARTIME=$SECONDS
export PATH=$PATH:$GOPATH/bin
export RC=0
export FABRIC_TLS
> $RESULTLOG

function runTests() {
   echo "Running fvt tests ..."
   tests="$(find $SCRIPTDIR -maxdepth 1 -name "*test.*sh")"

   for FABRIC_TLS in "true" "false"; do
      for cmd in $tests; do
        echo ""
        echo "*******************"
        export TESTCASE="${cmd##*/}"
        echo "${cmd}"
        echo "*******************"
        ${cmd}
        RC=$((RC+$?))
        $SCRIPTDIR/fabric-ca_setup.sh -R
        echo ""
        echo ""
        echo ""
      done
   done
}

TimeStamp
runTests > >( tee $RESULTLOG )
grep RC: $RESULTLOG
echo "Finished running fvt tests"
TESTCASE="fabric-ca-fvt"
CleanUp "$RC"
exit "$RC"
